package com.fr.lintcode;

import java.util.HashMap;
import java.util.Map;

public class Q384 {

	/**
	 * @param s: a string
	 * @return: an integer
	 */
	public int lengthOfLongestSubstring(String s) {
		// write your code here
		int max = 0;
		if (s == null) {
			return max;
		}
		int length = s.length();
		int left = 0;
		int right = 0;
		Map<Character, Integer> map = new HashMap<>();
		while(right < length) {
			char c = s.charAt(right);
			if(map.containsKey(c)) {
				left = Math.max(left, map.get(c) + 1);
			}
			map.put(c, right);
			max = Math.max(max, right - left + 1);
			right ++;
		}
		return max;
	}

}
